﻿using System;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using SD.Commons;
using SD.Commons.Helpers;
using SD.Entities;

namespace SD.DataAccess
{
    public class ContactAccess
    {
        public bool AddContact2(ContactEntity contactEntity)
        {
            try
            {
                var parameters = new Collection<SqlParameter>
                                     {
                                         new SqlParameter("@FirstName",contactEntity.FirstName),
                                         new SqlParameter("@Surname",contactEntity.Surname),
                                         new SqlParameter("@KnownAs",contactEntity.KnownAs),
                                         new SqlParameter("@OfficePhone",contactEntity.OfficePhone),
                                         new SqlParameter("@MobilePhone",contactEntity.MobilePhone),
                                         new SqlParameter("@StHomePhone",contactEntity.StHomePhone),
                                         new SqlParameter("@Email",contactEntity.Email),
                                         new SqlParameter("@ManagerId",contactEntity.ManagerId),
                                         new SqlParameter("@ContactTypeCode",contactEntity.ContactTypeCode),
                                         new SqlParameter("@BestContactMethodCode",contactEntity.BestContactMethodCode),
                                         new SqlParameter("@JobRole",contactEntity.JobRole),
                                         new SqlParameter("@Workbase",contactEntity.Workbase),
                                         new SqlParameter("@JobTitle",contactEntity.JobTitle),
                                         new SqlParameter("@IsActive",contactEntity.IsActive)
                                     }; 
                var result = SqlHelper.ExecuteNonQuery(DBSchemas.Addcontact,parameters);
                return result == 1;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
